<template>
  <!-- 登录页面 -->
  <div id="userdl">
    <h1>登录</h1>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="username"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit" class="btn"
          >登录/注册</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import { PostUser } from "../request/api.js";
export default {
  
  data() {
    return {
      username: "",
      password: "",
      userInfo:{}
    };
  },
  methods: {
    //登录请求
    onSubmit(values) {
      PostUser({ username: values.username, pwd: values.password,})
        .then((res) => {
          // console.log(res.data);
          window.sessionStorage.setItem('token', res.data.token)
          this.$router.push("/user")
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
};
</script>

<style lang="less" scoped>
#userdl {
  background-color: #efefef;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  text-align: center;
  h1 {
    font-size: 0.3rem;
    line-height: 0.5rem;
  }
  .btn {
    margin-top: 1rem;
    font-size: 0.2rem;
  }
}
</style>